import http from '@/utils/request'
import {removeTokenInfo , setTokenInfo} from '@/utils'

// 发送验证码
export const sendValidationCode = (mobile) => {
    return async (dispatch) => {
        const res = await http.get(`/sms/codes/${mobile}`)
      }
}

// 发送登陆请求
export const login = params => {

  return async (dispatch) => {

    const res = await http.post('/authorizations', params)
    const tokenInfo = res.data
    dispatch(saveToken(tokenInfo))
    setTokenInfo(tokenInfo)
  }
}
// 保存token在redux
export const saveToken = tokenInfo => {
  return {
    type: 'login/token',
    payload: tokenInfo
  }
}
export const logout = () => {
  return (dispatch) => {
    removeTokenInfo()

    dispatch({
      type: 'login/logout'
    })
  }
}